package org.example.controller;

import org.example.domain.JkCustomer;
import org.example.service.IShardingJDBCService;
import org.example.threadlocal.UserContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("/sharing_jdbc")
public class ShardingJDBCController {

    @Resource
    private IShardingJDBCService shardingJDBCService;

    @GetMapping("/selectByPrimaryKey")
    public JkCustomer selectByPrimaryKey(Long customerId)
    {
        return shardingJDBCService.selectByPrimaryKey(customerId);
    }

    @GetMapping("/testAop")
    public void testAop()
    {
        shardingJDBCService.testAop();
    }

    @GetMapping("/testShardingMaster")
    public void testShardingMaster()
    {
        UserContext.setUser("sharding");
        shardingJDBCService.testShardingMaster();
        UserContext.clear();
    }
}
